package com.scwatch.ext.domain;

import com.scwatch.core.domain.Site;
import com.scwatch.core.domain.User;
import com.scwatch.core.support.Siteable;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 地市州服务配置
 *
 * @author gjl
 *
 */
@Entity
@Table(name = "cms_city_config")
public class CityConfig implements java.io.Serializable,Siteable {
    private static final long serialVersionUID = 1L;


    private Integer id;

    /**
     * 父级
     */
    private Integer parentId;

    /**
     * 地市州名字
     */
    private String cityName;

    /**
     * 市州图标
     */
    private String cityImage;

    /**
     * 链接地址
     */
    private String url;

    /**
     * 是否同步数据
     */
    private Boolean isSyncData;

    /**
     * 链接是不是H5页面链接
     */
    private Boolean isH5;

    /**
     * 机构id
     */
    private Integer institutionId;

    /**
     * 机构名称
     */
    private String institutionName;

    /**
     * 机构json url
     */
    private String institutionUrl;

    /**
     * 机构接口域名
     */
    private String domainName;

    /**
     * 顺序
     */
    private Integer seq;

    /**
     * 是否发布 1，发布 2不发布
     */
    private String publish;


    /**
     * 创建日期
     */
    private Date createDate;

    /**
     * 更新日期
     */
    private Date udpateDate;

    /**
     * 站点
     */
    private Site site;

    /**
     * 用户
     */
    private User user;

    /**
     * 级别
     */
    private Integer level;



    private List<CityConfig> children = new ArrayList<CityConfig>(0);


    @Id
    @Column(name = "f_id", unique = true, nullable = false)
    @TableGenerator(name = "tg_cms_city_config", pkColumnValue = "cms_city_config", initialValue = 1, allocationSize = 10)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_cms_city_config")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "f_parent_id")
    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    @Column(name = "f_city_name", length =250)
    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    @Column(name = "f_city_image", length =500)
    public String getCityImage() {
        return cityImage;
    }
    public void setCityImage(String cityImage) {
        this.cityImage = cityImage;
    }

    @Column(name = "f_url", length =500)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(name = "f_is_syncdata", length = 1)
    public Boolean getSyncData() {
        return isSyncData;
    }

    public void setSyncData(Boolean syncData) {
        isSyncData = syncData;
    }

    @Column(name = "f_is_h5", length = 1)
    public Boolean getH5() {
        return isH5;
    }

    public void setH5(Boolean h5) {
        isH5 = h5;
    }

    @Column(name = "f_institution_id")
    public Integer getInstitutionId() {
        return institutionId;
    }

    public void setInstitutionId(Integer institutionId) {
        this.institutionId = institutionId;
    }

    @Column(name = "f_institution_name", length =250)
    public String getInstitutionName() {
        return institutionName;
    }

    public void setInstitutionName(String institutionName) {
        this.institutionName = institutionName;
    }

    @Column(name = "f_institution_url", length =250)
    public String getInstitutionUrl() {
        return institutionUrl;
    }

    public void setInstitutionUrl(String institutionUrl) {
        this.institutionUrl = institutionUrl;
    }

    @Column(name = "f_seq", nullable = false)
    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    @Column(name = "f_domain_name", length =250)
    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    @Column(name = "f_is_publish", length =2)
    public String getPublish() {
        return publish;
    }

    public void setPublish(String publish) {
        this.publish = publish;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "f_creation_date", nullable = false)
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "f_update_date")
    public Date getUdpateDate() {
        return udpateDate;
    }

    public void setUdpateDate(Date udpateDate) {
        this.udpateDate = udpateDate;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_site_id", nullable = false)
    public Site getSite() {
        return site;
    }

    public void setSite(Site site) {
        this.site = site;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_user_id")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "f_level", nullable = false)
    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentId")
    @OrderBy(value = "seq asc, id asc")
    public List<CityConfig> getChildren() {
        return this.children;
    }

    public void setChildren(List<CityConfig> children) {
        this.children = children;
    }

}
